package com.ckerchina.admin.ckadmin.service.mgr;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.ckerchina.admin.ckadmin.domain.mgr.MgrUser;

public class MgrUserDetail implements UserDetails {

	private static final long serialVersionUID = 1L;

	private MgrUser user;

	private boolean isEnable = true;

	private Collection<? extends GrantedAuthority> authorities;

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	@Override
	public String getPassword() {
		return user.getPwd();
	}

	@Override
	public String getUsername() {
		return user.getName();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return isEnable;
	}

	public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
		this.authorities = authorities;
	}

	public MgrUser getUser() {
		return user;
	}

	public void setUser(MgrUser user) {
		this.user = user;
	}

	public boolean isEnable() {
		return isEnable;
	}

	public void setEnable(boolean isEnable) {
		this.isEnable = isEnable;
	}

	@Override
	public String toString() {
		if (user == null) {
			return super.toString();
		} else {
			return user.getName() ;
		}
	}

}
